const app = getApp();
Page({
  data: {
    //刷新页面标识
    reloadFlag:false,
    //昵称
    nickName: '',
    // 个人标签
    Innermonologue: [
    ],
    // 基本资料
    Capitalinformation: [
    ],
    // 详细资料
    Detailedinformation: [
    ],
    // 性格外貌
    Characterappearance: [
    ],
    // 详细资料
    Detailedinformation: [
    ],
    //形象照
    imagePhoto: '',
    //身份证照片
    idCardPhoto: '',
    //内心独白
    monologue: '',
    //头像
    headImage: '',
  },
  onLoad: function (options) {
    this.initPage();
  },
  onShow: function () {
    if (this.data.reloadFlag){
      this.initPage();
    }
  },
  goPersonalBaseInfoEdit: function () {
    wx.navigateTo({
      url: '../../pages/personalBaseInfoEdit/personalBaseInfoEdit'
    })
  },
  goPersonalDetailInfoEdit: function () {
    wx.navigateTo({
      url: '../../pages/personalDetailInfoEdit/personalDetailInfoEdit'
    })
  },
  Xinggewaimao: function () {
    wx.navigateTo({
      url: '../../pages/personalLookInfoEdit/personalLookInfoEdit'
    })
  },
  goPersonalLabelTagsEdit: function () {
    wx.navigateTo({
      url: '../../pages/personalLabelTagsEdit/personalLabelTagsEdit'
    })
  },
  goPersonalLabelsEdit: function () {
    wx.navigateTo({
      url: '../../pages/personalLabelsEdit/personalLabelsEdit'
    })
  },
  initPage: function () {
    wx.showLoading({
      title: '数据加载中。。。。',
    })
    var _this = this;
    var data = wx.getStorageSync('userInfo');
    var details = data.detail;
    var member = data.member;
    var personalLabelTagsTemp = data.detail.labels.split(',');
    var personalLabelTags = [];
    for (let item of personalLabelTagsTemp) {
      let obj = { 'text': item };
      personalLabelTags.push(obj);
    }
    _this.setData({
      nickName: member.nickName,
      Characterappearance: [
        { textone: '个性描述', texttwo: details.personalitys },
        { textone: '相貌自评', texttwo: details.lookss },
        { textone: '体型', texttwo: details.shapes },
        { textone: '魅力部位', texttwo: details.charms },
        { textone: '发型', texttwo: details.hairStyles },
        { textone: '发色', texttwo: details.hairColors },
        { textone: '脸型', texttwo: details.faces }
      ],
      Capitalinformation: [
        { textone: '姓名', texttwo: member.name },
        { textone: '身份证号', texttwo: member.idCard },
        { textone: '生日', texttwo: member.birth.split(' ')[0] },
        { textone: '身高', texttwo: member.height != 0 ? member.height : '' + 'cm' },
        { textone: '体重', texttwo: member.weight + 'kg' },
        { textone: '年龄', texttwo: member.age != 0 ? member.age : '' },
        { textone: '籍贯', texttwo: member.nativePlaces },
        { textone: '月薪', texttwo: member.moneys },
        { textone: '工作单位', texttwo: member.company },
        { textone: '职业', texttwo: member.zys + ' ' + member.zyms },
        { textone: '学历', texttwo: member.educations },
        { textone: '婚姻状况', texttwo: member.marrys },
        { textone: '所在地区', texttwo: member.cregion.name + member.xregion.name }
      ],
      Innermonologue: personalLabelTags,
      // 性格爱好
      Characterhobby: [
        { textone: '运动', texttwo: details.motions },
        { textone: '食物', texttwo: details.foods },
        { textone: '书籍', texttwo: details.books },
        { textone: '电影', texttwo: details.movies },
        { textone: '业余爱好', texttwo: details.hobbys },
        { textone: '旅游', texttwo: details.tourisms },
        { textone: '关注节目', texttwo: details.programs },
        { textone: '娱乐新鲜', texttwo: details.amuses }
      ],
      //详细资料
      Detailedinformation: [
        { textone: '民族', texttwo: member.nations },
        { textone: '生肖', texttwo: member.zodiacs },
        { textone: '星座', texttwo: member.constellations },
        { textone: '血型', texttwo: member.bloods},
        { textone: '有无子女', texttwo: member.childrens },
        { textone: '购车情况', texttwo: member.cars },
        { textone: '住房情况', texttwo: member.rooms }
      ],
      headImage: member.img,
      imagePhoto: 'http://appapp.b0.upaiyun.com' + member.img,
      idCardPhoto: 'http://appapp.b0.upaiyun.com' + member.sfzurl,
      monologue: member.monologue,
    },function(){
      wx.hideLoading();
    });
  },
  goPersonalMonologueEdit: function (e) {//编辑内心独白
    wx.navigateTo({
      url: '../../pages/personalMonologueEdit/personalMonologueEdit',
    });
  },
  doChangeHeadImg:function(e){
    var _this = this;
    wx.chooseImage({
      count: 1,
      success: function (res) {
        var tempFilePaths = res.tempFilePaths;//文件临时访问路径
        var tempFiles = res.tempFiles;//文件临时存储对象
        wx.uploadFile({
          url: app.globalData.SERVICE.USERCENTER.AVATARUPLOAD,
          filePath: tempFilePaths[0],
          name: 'imgFile',
          success: function (res) {
            if (typeof (res.data) == 'string') {
              var data = JSON.parse(res.data);
            }
            let url = data.url;
            app.doReq(app.globalData.SERVICE.USERCENTER.USERHEAD, {
              "id": app.globalData.userid,
              "type": 1,
              "path": url
            }, 'get', function (res) {
              var data = res.data;
              console.log(url);
              if (data.code == 200) {
                wx.showToast({
                  title: '头像上传成功~',
                  icon: 'success',
                  duration: 1000,
                });
                _this.setData({
                  imagePhoto: 'http://appapp.b0.upaiyun.com'+url
                })
              }
            });
          }
        })
      },
    })
  },
  goUpload:function(){
        wx.navigateTo({
          url: '../../pages/papersUpload/papersUpload',
        })
  }
});